/**
 * @author Daivd chow
 *
 * 下午05:31:48
 */
package com.cbts.util;

import java.util.ArrayList;
import java.util.List;

import org.comet4j.core.CometContext;
import org.comet4j.core.CometEngine;

import com.cbts.dao.BusinessTravelListDao;
import com.cbts.dao.UserInfoDao;
import com.cbts.dao.impl.UserInfoDaoImpl;

public class MessageThread implements Runnable {

	private UserInfoDao userInfoDao;
	
	private BusinessTravelListDao businessTravelListDao;
	 
	/* 
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		// zqd 下午05:31:48
		//test，先读取user_info中的人数试试。。。
		
		
		userInfoDao=(UserInfoDao)SpringApplicationContext.getSpringBean("userInfoDao");
		businessTravelListDao=(BusinessTravelListDao)SpringApplicationContext.getSpringBean("businessTravelListDao");
		//用户数
		//待审核的businessTravel
		//待报销的businessTravel
		while(true){
			//发一个数组
			List<Long> list=new ArrayList<Long>();
			list.add(userInfoDao.getCount(null, null));
			list.add(businessTravelListDao.getCount("and verifierStatus = '待审核'", null));
			list.add(businessTravelListDao.getCount("and verifierStatus = '待报销'", null));
			CometEngine engine=CometContext.getInstance().getEngine();
			//System.out.println(list.get(0)+":"+list.get(1)+":"+list.get(2));
			engine.sendToAll(Constant.CHANNEL,list);
			
			try{
				Thread.sleep(5000);	//休眠
			}catch(Exception e){
				e.printStackTrace();
			}
			
		}
	}

}
